package com.example.kotlindemo.反射

import java.lang.reflect.Field
import kotlin.reflect.KClass

@MyAnnotation
@MyTag("Kotlin")
@MyTag("java")
class reflectdemo {

    @JvmField
    @Transient
    @Volatile
    var myField = 66



}

fun main() {
    val hClass = Class.forName("com.example.kotlindemo.反射.Human")
    val kClz = Human::class
    val _hClz = Human::class.java

    _hClz.declaredClasses //
    val fields:Array<Field> = _hClz.fields
    _hClz.getDeclaredField("age")


//    val get = kClz.members.stream().filter {
//        it.name = "name"
//    }.findAny().get()


    val hClass_1 = Human::class.java
    val human  = hClass_1.newInstance() as Human

    val kClass_1 = Human::class
//    kClass_1.members todo kclass createIntance() change objectInstance
    val javaClass = kClass_1.constructors.stream().filter {
        it.parameters.size == 1
    }.findAny().get().javaClass

    javaClass.newInstance()

    val declaredMethod = hClass_1.getDeclaredMethod("say", String::class.java)
    declaredMethod.isAccessible = true
    declaredMethod.invoke(human,"hello luge")


}